package com.graduate.front.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.graduate.common.entity.Handle;
import com.graduate.common.entity.Users;
import com.graduate.common.service.IHandleService;
import com.graduate.common.vo.HandleVo;
import com.graduate.front.pojo.MyUser;
import com.graduate.front.pojo.TableData;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.management.Query;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author bwzfy
 * @create 2021/5/15
 **/
@Controller
@RequestMapping("/handle")
public class HandleController extends BaseController {

    @ResponseBody
    @GetMapping("/user/account")
    public TableData<HandleVo> getHandleAccount(HttpSession session) {
        MyUser user = (MyUser) session.getAttribute("user");
        // 查询办理表中的这个userid的数据
        QueryWrapper<Handle> wrapper = new QueryWrapper<>();
        wrapper.eq("userId", user.getId());
        wrapper.eq("status", 0);
        List<Handle> list = handleService.list(wrapper);
        TableData<HandleVo> tableData = new TableData<>();
        tableData.setCount(list.size());
        tableData.setData(list.stream().map(handle -> {
            HandleVo handleVo = new HandleVo();
            BeanUtils.copyProperties(handle, handleVo);
            handleVo.setHouse(houseService.getById(handle.getHid()));
            return handleVo;
        }).collect(Collectors.toList()));
        return tableData;
    }

}
